package cn.laixueit.controller;

import cn.laixueit.pojo.Cart;
import cn.laixueit.pojo.Order;
import cn.laixueit.pojo.User;
import cn.laixueit.result.Result;
import cn.laixueit.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    @ResponseBody
    public Result addOrder(@RequestBody List<Cart> carts, HttpSession session){
        User user = (User) session.getAttribute("u");
        Integer uid = user.getId();
        orderService.addOrder(carts,uid);
        return new Result();
    }

    @GetMapping("/findAll")
    @ResponseBody
    public Result findAll(HttpSession session){
        User user = (User) session.getAttribute("u");
        Integer uid = user.getId();
        List<Order> orderList = orderService.findAll(uid);
        return new Result(200,orderList);
    }


    @PostMapping("/sendGoods")
    @ResponseBody
    public Result sendGoods(@RequestBody List<Order> orders,Integer aid){
        orderService.sendGoods(orders,aid);
        return new Result();
    }


}
